
using System;
using System.Data;
using System.Data.SqlClient;
using ERP_RORZE_ORDER.Common;
using ERP_RORZE_ORDER.Common.ValueObject;
using ERP_RORZE_TOOL.DBAccess;

namespace ERP_RORZE_ORDER.DBAccess
{

	public class PurposeDAO : BaseDAO
	{
        #region Basic Method

        public static DataTable GetAll()
        {
            return ExcuteProcedure(OrderConstants.StoreProcedure.Purpose.GetAll);
        }

        public static DataTable GetAll(string storedProc)
        {
            return ExcuteProcedure(storedProc);
        }
        public static DataTable GetOne(string purposeId)
        {
            try
            {
                var parameters = new SqlParameter[]
                    {
						CreateParameter("@PurposeID", SqlDbType.NVarChar, purposeId)
                    };
                return ExcuteProcedure(OrderConstants.StoreProcedure.Purpose.GetOne, parameters);

            }
            catch (Exception e)
            {
                throw new BaseDAO.MyException(e);
            }

        }

        public static Purpose LoadOne(string purposeId)
        {
            Purpose o = new Purpose();
            DataTable dt = GetOne(purposeId);
            if (dt.Rows.Count > 0)
            {
                //o.ID = int.Parse(dt.Rows[0][OrderConstants.Entities.Purpose.FieldName.ID].ToString());
                o.PurposeID = dt.Rows[0][OrderConstants.Entities.Purpose.FieldName.PurposeID].ToString();
                o.EnglishName = dt.Rows[0][OrderConstants.Entities.Purpose.FieldName.EnglishName].ToString();
                o.JapanName = dt.Rows[0][OrderConstants.Entities.Purpose.FieldName.JapanName].ToString();
                o.VietName = dt.Rows[0][OrderConstants.Entities.Purpose.FieldName.VietName].ToString();

            }

            return o;
        }


        public static int Insert(Purpose o)
        {
            try
            {
                var parameters = new SqlParameter[]
                    {
                        CreateParameter("@PurposeID", SqlDbType.NVarChar, o.PurposeID),
                        CreateParameter("@EnglishName", SqlDbType.NVarChar, o.EnglishName),
                        CreateParameter("@JapanName", SqlDbType.NVarChar, o.JapanName),
                        CreateParameter("@VietName", SqlDbType.NVarChar, o.VietName),
                    };

                return ExecuteNonQueryProcedure(OrderConstants.StoreProcedure.Purpose.Insert, parameters);

            }
            catch (Exception e)
            {
                throw new BaseDAO.MyException(e);
            }

        }

        public static int Update(Purpose o)
        {
            try
            {
                var parameters = new SqlParameter[]
                    {
                        CreateParameter("@TempID", SqlDbType.NVarChar, o.TempId),
                        CreateParameter("@PurposeID", SqlDbType.NVarChar, o.PurposeID),
                        CreateParameter("@EnglishName", SqlDbType.NVarChar, o.EnglishName),
                        CreateParameter("@JapanName", SqlDbType.NVarChar, o.JapanName),
                        CreateParameter("@VietName", SqlDbType.NVarChar, o.VietName),
                    };

                return ExecuteNonQueryProcedure(OrderConstants.StoreProcedure.Purpose.Update, parameters);
            }
            catch (Exception e)
            {
                throw new BaseDAO.MyException(e);
            }
        }

        public static int Delete(Purpose o)
        {
            try
            {
                var parameters = new SqlParameter[]
                    {
                        CreateParameter("@PurposeID", SqlDbType.NVarChar, o.PurposeID)
                    };

                return ExecuteNonQueryProcedure(OrderConstants.StoreProcedure.Purpose.Delete, parameters);
            }
            catch (Exception e)
            {
                throw new BaseDAO.MyException(e);
            }
        }

        public static DataTable GetTemplateTable()
        {
            DataTable table = new DataTable("243_Purpose");

            return table;
        }


        #endregion
    }
	
}
